package com.pluser.mq.vo;

import java.io.Serializable;
import java.util.Hashtable;
import java.util.Map;

/**
 * 
 * QueueManagerInfo class
 * @author pluser
 * @version 1.0
 * @date 2014-05-03
 * @modifiedHis
 *
 * @description
 * includes queue manager's name、host、port and etc.
 */
public class QueueManagerInfo implements Serializable {

	private static final long serialVersionUID = -6898794011101536624L;
	
	private String name;
	@SuppressWarnings("rawtypes")
	private Hashtable properties = new Hashtable();
	
	/**
	 * constructor
	 * @param name queue manager's name
	 * @throws IllegalArgumentException if name is null or empty
	 */
	public QueueManagerInfo(String name) throws IllegalArgumentException {
		
		if(name == null || name.trim().length() == 0) {
			throw new IllegalArgumentException("queue manager's name is null or empty");
		}
		
		this.name = name;
	}
	
	/**
	 * constructor
	 * @param name queue manager's name
	 * @param prop queue manager's properties that includes host、port and etc.
	 * @throws IllegalArgumentException if name is null or empty, prop is null 
	 */
	@SuppressWarnings("rawtypes")
	public QueueManagerInfo(String name, Hashtable prop)
			throws IllegalArgumentException {
		
		if(name == null || name.trim().length() == 0) {
			throw new IllegalArgumentException("queue manager's name is null or empty");
		}
		
		if(prop == null) {
			throw new IllegalArgumentException("queue manager's prop is null");
		}
		
		this.name = name;
		this.properties = prop;
	}
	
	/**
	 * 
	 * @return name of queue manager
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * 
	 * @param name queue manager's name
	 * @throws IllegalArgumentException
	 */
	public void setName(String name) throws IllegalArgumentException {
		
		if(name == null || name.trim().length() == 0) {
			throw new IllegalArgumentException("queue manager's name is null or empty");
		}
		
		this.name = name;
	}

	/**
	 * 
	 * @return queue manager's properties that includes host、port and etc.
	 */
	@SuppressWarnings("rawtypes")
	public Hashtable getProperties() {
		return properties;
	}

	/**
	 * 
	 * @param properties queue manager's properties that includes host、port and etc.
	 * @throws IllegalArgumentException
	 */
	@SuppressWarnings("rawtypes")
	public void setProperties(Hashtable properties) throws IllegalArgumentException {
		
		if(properties == null) {
			throw new IllegalArgumentException("queue manager's properties is null");
		}
		
		this.properties = properties;
	}
	
	/**
	 * 
	 * @return host of queue manager
	 */
	public String getHost() {
		return (String)properties.get("host");
	}
	
	/**
	 * 
	 * @param host queue manager's host
	 */
	@SuppressWarnings("unchecked")
	public void setHost(String host) {
		properties.put("host", host);
	}

	/**
	 * 
	 * @return port of queue manager
	 */
	public String getPort() {
		return (String)properties.get("port");
	}
	
	/**
	 * 
	 * @param port queue manager's port
	 */
	@SuppressWarnings("unchecked")
	public void setPort(String port) {
		properties.put("port", port);
	}
	
	/**
	 * 
	 * @return channel of queue manager
	 */
	public String getChannel() {
		return (String)properties.get("channel");
	}
	
	/**
	 * 
	 * @param channel queue manager's channel
	 */
	@SuppressWarnings("unchecked")
	public void setChannel(String channel) {
		properties.put("channel", channel);
	}
	
	/**
	 * 
	 * @return CCSID of queue manager
	 */
	public String getCCSID() {
		return (String)properties.get("CCSID");
	}
	
	/**
	 * 
	 * @param CCSID queue manager's CCSID
	 */
	@SuppressWarnings("unchecked")
	public void setCCSID(String CCSID) {
		properties.put("CCSID", CCSID);
	}
	
	/**
	 * 
	 * @param key key of properties
	 * @return
	 */
	public Object getProperty(String key) {
		return properties.get(key);
	}

	/**
	 * 
	 * @param propMap properties map container
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void addProperties(Map propMap) {
		properties.putAll(propMap);
	}
	
	/**
	 * and property to queue manager's properties
	 * @param key
	 * @param value
	 */
	@SuppressWarnings("unchecked")
	public void addProperty(String key, Object value) {
		properties.put(key, value);
	}
	
	/**
	 * remove property
	 * @param key
	 * @return
	 */
	public Object removeProperty(String key) {
		return properties.remove(key);
	}
	
	/**
	 * 
	 * @param key
	 * @return
	 */
	public boolean containsPropertyKey(String key) {
		return properties.containsKey(key);
	}
	
	/**
	 * 
	 * @param value
	 * @return
	 */
	public boolean containsPropertyValue(Object value) {
		return properties.containsValue(value);
	}
	
}
